/**
 * FleetBannerBillboard.java
 *
 * Roslan's Remake of MOO in 3D using Ardor3D
 * (C) 2011 Roslan Amir. All rights reserved.
 */

package com.roslan.games.moo3d.spatial;

import com.ardor3d.image.Texture;
import com.ardor3d.image.TextureStoreFormat;
import com.ardor3d.math.ColorRGBA;
import com.ardor3d.renderer.state.MaterialState;
import com.ardor3d.renderer.state.RenderState.StateType;
import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.extension.BillboardNode;
import com.ardor3d.scenegraph.shape.Quad;
import com.ardor3d.util.TextureManager;

/**
 * Comments go here.
 * 
 * @author Roslan Amir
 * @version 1.0 - Mar 1, 2011
 */
public class FleetBannerBillboard extends BillboardNode {

	/**
	 * The banner images
	 */
	private static final String[] IMAGES_BANNER = { 
//		"images/banner_01_red.png", 
//		"images/banner_02_yellow.png", 
//		"images/banner_03_green.png",
//		"images/banner_04_grey.png", 
//		"images/banner_05_blue.png", 
//		"images/banner_06_brown.png", 
//		"images/banner_07_purple.png",
//		"images/banner_08_orange.png" };
		"images/banner_01_red_border.jpg", 
		"images/banner_02_yellow_border.jpg", 
		"images/banner_03_green_border.jpg",
		"images/banner_04_grey_border.jpg", 
		"images/banner_05_blue_border.jpg", 
		"images/banner_06_brown_border.jpg", 
		"images/banner_07_purple_border.jpg",
		"images/banner_08_orange_border.jpg" };

	/**
	 * The index into the array (indicating the color)
	 */
	private int bannerIndex;

	/**
	 * Default no-arg constructor.
	 * 
	 * @param index - the race banner index
	 */
	public FleetBannerBillboard(int index) {
		super("FleetBannerBillboardNode");
		this.bannerIndex = index;
		this.setAlignment(BillboardAlignment.ScreenAligned);

		/*
		 * Sets the Material State for this billboard node.
		 */
		final MaterialState ms = new MaterialState();
		ms.setEnabled(true);
		ms.setEmissive(ColorRGBA.WHITE);
		// ms.setAmbient(ColorRGBA.WHITE);
		// ms.setDiffuse(ColorRGBA.WHITE);
		// ms.setSpecular(ColorRGBA.WHITE);
		this.setRenderState(ms);

//		final Quad quad = new Quad("FleetBannerQuad", 0.425, 0.5); // image size: 85 x 100
		final Quad quad = new Quad("FleetBannerQuad", 0.485, 0.56); // image size: 97 x 112

		final TextureState ts = new TextureState();
		final Texture texture = TextureManager.load(IMAGES_BANNER[index], Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessCompressedFormat, true);
		ts.setEnabled(true);
		ts.setTexture(texture);
		quad.setRenderState(ts);

		this.attachChild(quad);
	}

	/**
	 * Set the new banner for this <code>FleetBannerBillboard</code> instance.
	 * 
	 * @param index - the new banner index
	 */
	public void setBanner(int index) {
		if (index == this.bannerIndex)
			return;
		this.bannerIndex = index;
		TextureState ts = (TextureState) this.getLocalRenderState(StateType.Texture);
		ts.setTexture(TextureManager.load(IMAGES_BANNER[index], Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessCompressedFormat, true));
	}

}
